<?php
class Admin_Model_SidebarModule extends Zend_Db_Table{
	protected $_name = 'sidebar_module';
	protected $_primary = 'module_id';
	/* Link tham khao : http://framework.zend.com/manual/en/zend.db.table.html */
	////////////
	/* select*/
	//////////
	
	public function selectModuleByCode($code)
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/sidebarmodule/route/selectModuleByCode/code/".$code);
		$return = json_decode(json_encode((array) simplexml_load_string($return->getBody())),1);
		
		for ($i=0;$i <count($return);$i++)
				$data[$i] = $return['row_'.$i];
		
		return $data;		
	}
	
	public function selectModuleBySortOrder($sort_order,$module_code)
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/sidebarmodule/route/selectModuleBySortOrder/sort_order/".$sort_order."/module_code/".$module_code);
		$return = json_decode(json_encode((array) simplexml_load_string($return->getBody())),1);
		
		for ($i=0;$i <count($return);$i++)
				$data[$i] = $return['row_'.$i];
		
		return $data;		
	}
	
	////////////
	/* insert*/
	//////////
	public function insertModule($data)
	{// co dung
		$data['route'] = "insertModule";
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restPost("/sidebarmodule", $data);

		return $return->getBody();			
	}
	
	////////////
	/* update*/
	//////////
	/*public function updateTempTable($id,$title,$content)
	{
		$adapter = $this->getDefaultAdapter();
		try {	
				$adapter->beginTransaction();
				$where = $adapter->quoteInto('id = ?', $id);
				$adapter->update('temp',array('title'=>$title,'content'=>$content),$where);
				$adapter->commit();
		}
		catch (Zend_Db_Table_Exception $e) {
			$adapter->rollBack();
			return -1;
		}
		return 1;
	}*/
	public function updateSidebar($sort,$module)
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restPut("/sidebarmodule/route/updateSidebar/sort/".urlencode($sort)."/module/".urlencode($module));
		return $return->getBody();		
	}
	
	////////////
	/* delete*/
	//////////
	public function deleteModuleByCode($code)
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restDelete("/sidebarmodule/route/deleteModuleByCode/code/".$code);
		return $return->getBody();		
	}
}